<template>
    <div>
        <ul class="item-box" v-show="!listIsZero">
            <li v-for="(item,index) in listData.data" :key="index">
                <el-row>
                    <el-col :span="4">
                        <img class="itemlogo displayB" width="150px" height="110px" style="max-width: 100%;" :src="item.st_photo_just" alt="" />
                    </el-col>
                    <el-col :span="16">
                        <div class="task-content-box">
                            <router-link class="task-tit" :to="{ path: '/workbench/details', query: { pid: item.p_id}}">{{item.p_name}}</router-link>
                            <p class="task-date">创建于 {{item.p_create_time}}</p>
                            <div class="task-item-exp">
                                <span><i class="color-sign">{{state_type}}</i></span>
                                <span>竞标数：<i>{{item.p_bidding}}</i></span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div>
                            <p class="task-money">￥{{item.p_budget | re_p_budget}}</p>
                            <p class="zb-days">{{item.p_cycle}}{{item.p_cycle_type | rep_cycle_type}}</p>
                            <p class="operation_box">
                                <span @click="changeState(item.p_id)">发布</span>
                                <span @click="editFun(item.p_id)">编辑</span>
                                <span @click="delFun(item.p_id)">删除</span>
                            </p>
                        </div>
                    </el-col>
                </el-row>
            </li>
        </ul>

        <!-- 分页 -->
        <div class="pagination text-right" v-show="!listIsZero">
            <el-pagination @current-change="handleCurrentChange" layout="total, prev, pager, next" :total="listData.total"></el-pagination>
        </div>

        <!-- 暂无数据 -->
        <div class="text-center" style="margin-top: 130px;" v-show="listIsZero">
            <img src="../../assets/images/empty.jpg" height="200" alt="">
            <p class="tip-small">暂无数据</p>
        </div>

    </div>
</template>
<script>
    
    import '../../assets/css/workbench.css'
    export default {
        data(){
            return{
                activeName: '1',
                currentPage: 1,
                listData: {},
                listIsZero: false,  //暂无数据
            }
        },
        filters: {
            //项目金额
            re_p_budget: function (value) {
                var val = 0;
                if (value == 1){
                    val = '3000以下';
                }else if (value == 2){
                    val = '3000-5000';
                }else if (value == 3){
                    val = '5000-10000';
                }else if (value == 4){
                    val = '10000-50000 ';
                }else if (value == 5){
                    val = '50000-100000';
                }else if (value == 6){
                    val = '100000 以上';
                }
                return val;
            },
            //项目周期单位
            rep_cycle_type: function(value){

                var val = '';
                if(value == 1){
                    val = '天';
                }else if(value == 2){
                    val = '周';
                }else if(value == 3){
                    val = '月';
                }
                return val;
            },
        },
        computed: {
            state_type: function(){
                if(this.activeName == '1'){
                    return '待发布'
                }else if(this.activeName == '2'){
                    return '待选标'
                }else if(this.activeName == '3'){
                    return '竞标中'
                }else if(this.activeName == '4'){
                    return '审核失败'
                }else if(this.activeName == '5'){
                    return '已完成'
                }
            },
        },
        methods: {
            init(){
                var _this = this;
                this.$httpGet('/api/index/Workbench/myProjectList',{
                    'p_status': _this.activeName,
                    'p_uid': window.localStorage.uid,
                    'page': _this.currentPage
                }).then(response => {
                    
                    if(response.code == 200){
                        
                        _this.listData = response.msg;
                        _this.listIsZero = false;

                    }else if(response.code == 301){  //暂无数据
                        _this.listIsZero = true;
                    }else{
                        this.$message({
                            message: response.msg,
                            type: 'warning'
                        });
                    }

                })
            },
            handleClick(tab, event) {
                
                this.init();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.init();
            },
            //修改状态（关闭、已完成、发布） 
            changeState(pid){

                var _this = this;
                this.$httpGet('/api/index/Workbench/updateProjectStatus',{
                    'p_uid': window.localStorage.uid,
                    'p_id': pid
                }).then(response => {
                    
                    if(response.code == 200){
                        
                        this.$message({
                            message: response.msg,
                            type: 'success'
                        });
                        _this.init();

                    }else{
                        this.$message({
                            message: response.msg,
                            type: 'warning'
                        });
                    }

                })
            },
            //删除
            delFun(pid){

                var _this = this;

                this.$confirm('是否确认删除该需求?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    
                    //删除需求
                    this.$httpGet('/api/index/Workbench/delProject',{
                        'p_uid': window.localStorage.uid,
                        'p_id': pid
                    }).then(response => {
                        
                        if(response.code == 200){
                            
                            this.$message({
                                message: response.msg,
                                type: 'success'
                            });
                            _this.init();

                        }else{
                            this.$message({
                                message: response.msg,
                                type: 'warning'
                            });
                        }

                    })

                }).catch(() => {
                            
                });
            },
            //编辑
            editFun(pid){
                this.$router.push({path: '/publishedit', query: {'pid': pid}})
            },
        },
        mounted(){
            this.init();
        },
    }
</script>